home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / www / cgi-bin / osearch-cgi < prev    next >
Encoding:
Text File  |  1996-11-11  |  11.5 KB  |  302 lines

  1. #!/usr/sbin/perl
  2. # $Id: osearch-cgi.m,v 1.5 1996/11/04 15:47:34 murphy Exp $
  3. #
  4. # osearch-cgi - CGI search engine for Oasis
  5. #
  6. # $Log: osearch-cgi.m,v $
  7. # Revision 1.5  1996/11/04  15:47:34  murphy
  8. # add DT_utilities to virtual doc root
  9. #
  10. # Revision 1.4  1996/10/29  21:28:22  murphy
  11. # changes necessary to support forum 96 CD
  12. #
  13. # Revision 1.3  1996/04/22  13:38:29  DTjanitor
  14. # change .www references to .www_6.0
  15. #
  16. # Revision 1.2  1996/02/15  22:57:02  dave
  17. # fixed up incorrect attempts at using ~dave
  18. #
  19. # Revision 1.1  1996/02/15  19:47:57  dave
  20. # adding in collapsed cgi-bin{int,ext,cd} files into their .m new forms
  21. #
  22. # Revision 1.1  1995/09/11  23:17:51  dave
  23. # Initial revision
  24. #
  25. # Revision 1.5  1995/03/11  01:40:27  dave
  26. # NOW osearch IS bossv osearch-cgi! for .html files to work for URLs (distinguishing doc from  path (see bottom of file))
  27. #
  28. # Revision 1.4  1995/03/11  00:38:26  dave
  29. # not finished but need to check these in to test 'em at work
  30. #
  31. # Revision 1.3  1995/02/16  17:52:54  dave
  32. # modified to refer to cgi-lib.pl locally & added cgi-lib.pl local copy
  33. #
  34. # Revision 1.2  1995/02/15  23:23:37  dave
  35. # updating incorrect html syntax and robustifying the code
  36. #
  37. #
  38.  
  39. require('cgi-lib.pl') || die "can\'t require cgi-lib.pl: $!";
  40.  
  41. $request_method = $ENV{'REQUEST_METHOD'};
  42. $query_string = $ENV{'QUERY_STRING'};
  43. $path_info = $ENV{'PATH_INFO'};
  44. $path_info =~ s/^\///; $path_info =~ s/\// /;
  45. $content_length = $ENV{'CONTENT_LENGTH'};
  46.  
  47. #####################################
  48. # Setup/Define Machine-Specific stuff
  49. #
  50. # DEFINE THE SERVER NAME FOR THE oksvr RUN OUT OF /etc/init.d/okserver:
  51.  
  52. chop($server=`hostname`);
  53.  
  54. #get user home directory from this file evaluates $userHome
  55. eval (`cat "/tmp/.userhome_$ENV{'SERVER_PORT'}"`);
  56.  
  57. # get location of CDROM mount point evaluates $cdromMount
  58. eval (`cat "/tmp/.cdlocation_$ENV{'SERVER_PORT'}"`);
  59.  
  60.  
  61. # DEFINE WHAT THE FULSEARCH PATH WILL BE SO WE CAN BUILD THE URLs:
  62. #
  63. # Make sure the value of the $OksvrSearchRoot variable inside the
  64. # /usr/people/dave/.DT_OksvrRoot file, specified below, is equivalent
  65. # to what the OKSVR_ROOT variable is defined to be inside the
  66. # /etc/init.d/okserver script
  67. # AND have it's path from the root directory of "/" be whatever makes
  68. # sense for you on your server machine--we originally put it in
  69. # /usr/tmp but this became unreliable since /usr/tmp/ IS "fair game"
  70. # for being completely cleaned out at any time.
  71. # For example, if /etc/init.d/okserver has defined:
  72. # OKSVR_ROOT=/usr/local/www/toolbox/searchtools
  73. # then the /usr/people/dave/.DT_OksvrRoot file should consist of the
  74. # following (starting from and including the `$' (dollar) sign:
  75. #    $OksvrSearchRoot="/usr/local/www/toolbox/searchtools" ;
  76. #
  77. $DocumentRoot="$ENV{'DOCUMENT_ROOT'}/toolbox/searchtools";
  78. chop($OasisCmdPort = `cat "$ENV{'DOCUMENT_ROOT'}/../logs/oksrv.port"`);
  79. $DT_utilities="$ENV{'DOCUMENT_ROOT'}/../DT_utilities";
  80.  
  81. $OksvrSearchRoot = "$OksvrSearchRoot/toolbox/all" ;
  82.  
  83.  
  84. ########################################
  85. # Print standard document header
  86. #    title      - document title (will also appear as H1 text)
  87. #    titleimg   - if used, will display instead of H1 title (title will be
  88. #                 ALT= text)
  89. sub header {
  90.     local ($title,$titleimg) = @_;
  91.  
  92.     print &PrintHeader;
  93.     print "<HTML>\n";
  94.     print "<HEAD>\n";
  95.     print "<TITLE>$title</TITLE>\n";
  96.     print "<LINK rev=\"made\" href=\"mailto:DTjanitor\@sgi.com\">\n";
  97.     print "</HEAD>\n\n";
  98.  
  99.     print "<BODY>\n";
  100.     print "<H1>";
  101.     if ($titleimg) {
  102.         print "<img align=\"center\" src=\"$titleimg\"><img src=\"/toolbox/www/images/space40.gif\">$title";
  103.     } else {
  104.         print "$title";
  105.     }
  106.     print "</H1>\n";
  107.     print "<h3><a href=\"/toolbox/DT.html\">HUB</a> | <a href=\"/toolbox/www/cgi-bin/pheedbak-cgi/toolbox/www/cgi-bin/?osearch-cgi\">Pheedbak</a> | <a href=\"/toolbox/DTtree.html\">Tree</a> | <a href=\"/toolbox/DTtopic.html\">Topic</a> | <a href=\"/toolbox/DTalfabetic.html\">A-Z</a> | <a href=\"/toolbox/DThot.html\">Hot</a> | <a href=\"/toolbox/DTnew.html\">New</a><img src=\"/toolbox/www/images/space90.gif\"><img align=\"middle\" alt=\"Silicon Graphics, Inc.\" src = \"/toolbox/www/images/sgilogosm.gif\"></h3>";
  108.     print "<HR size=\"4\">\n";
  109. }
  110.  
  111. ########################################
  112. # Print standard document footer
  113. # The following hidden variables may be imbedded in the form:
  114. #   back_url            - URL back to form
  115. #   back_url_image      - Image for back link
  116. #   back_url_label      - Label for back link (will be ALT= text if image)
  117. #   return_url          - URL to return to document
  118. #   return_url_image    - Image for return link
  119. #   return_url_label    - Label for return link (will be ALT= text if image)
  120. # This will also print any icons for areas specified in PATH_INFO.
  121. sub footer {
  122.     if ($in{'back_url'}) {
  123.         if ($in{'back_url_image'}) {
  124.             print "<BR><A HREF=\"$in{'back_url'}\"><IMG SRC=\"$in{'back_url_image'}\" ALT=\"\">$in{'back_url_label'}</A>\n";
  125.         } else {
  126.             print "<BR><A HREF=\"$in{'back_url'}\"><B>$in{'back_url_label'}</B></A>\n";
  127.         }
  128.     }
  129.     if ($in{'return_url'}) {
  130.         if ($in{'return_url_image'}) {
  131.             print "<BR><A HREF=\"$in{'return_url'}\"><IMG SRC=\"$in{'return_url_image'}\" ALT=\"\">$in{'return_url_label'}</A>\n";
  132.         } else {
  133.             print "<BR><A HREF=\"$in{'return_url'}\"><B>$in{'return_url_label'}</B></A>\n";
  134.         }
  135.     }
  136.     print "<BR>\n";
  137.     print "<hr size=\"4\">\n";
  138.     print "<p><FONT SIZE=\"-1\">DT pheedbak and comments are <i>always</i> \n";
  139.     print "appreciated by\n";
  140.     print "<A HREF=\"/toolbox/www/cgi-bin/pheedbak-cgi/toolbox/www/cgi-bin?DTsearch-cgi\">DTjanitor\@.sgi.com</A>. </FONT>\n";
  141.     print "<P>\n";
  142.  
  143.     print "<A HREF=\"/toolbox/sgi_info.html\"><FONT SIZE=\"-3\">Copyright © 1995, Silicon Graphics, Inc.</FONT></A>\n";
  144.     print "</BODY>\n";
  145.     print "</HTML>\n";
  146. }
  147.  
  148. #######################################################
  149. # Remove duplicate documents from oasiscmd query output
  150. sub remove_dups {
  151.     local(@oasis) = @_;
  152.     local($ptr,$title,$type,$path,$url,@noasis);
  153.  
  154.     foreach $_ (@oasis) {
  155.     ($ptr,$title,$type,$path) = (/^(\d+)\.\s+(.*)\s+(\d+)\s*(\S*)$/);
  156.     $url = $path;
  157.     $url =~ s/$OksvrSearchRoot\/[^\/]+\/toolbox//;
  158.     next if ($title{$url} eq $title);
  159.     $title{$url} = $title;
  160.     $ptr{$url} = $ptr;
  161.     $type{$url} = $type;
  162.     }
  163.     foreach $url (sort keys(%title)) {
  164.     push(@noasis,"$ptr{$url}. $title{$url} $type{$url} $url");
  165.     }
  166.     @noasis;
  167. }
  168.  
  169. &ReadParse();           # Get output from form
  170.  
  171. ##########################################################################
  172. # Generate an error if no keywords or doctitle and if no sub-database name
  173. unless (($in{'keywords'} || $in{'doctitle'}) && $in{'subset'}) {
  174.     &header("DT Search error!","/toolbox/www/images/OasisIII_icon.gif");
  175.     unless ($in{'keywords'} || $in{'doctitle'}) {
  176.         print "<h2>You must specify search criteria!</H2>\n";
  177.     } elsif (! $in{'subset'}) {
  178.         print "<h2>You must specify an area to search!</H2>\n";
  179.     }
  180.     &footer;
  181.     exit 1;
  182. }
  183. # (else) go with the "successful" header
  184. &header("DT Search Results...","/toolbox/www/images/OasisIII_icon.gif");
  185.  
  186.  
  187. ######################################################
  188. # Setup the oasiscmd command line from the form output
  189. #
  190. #$command = "$cdromMount/bin/oasiscmd -p $OasisCmdPort ";
  191. $command = "$DT_utilities/oasiscmd -p $OasisCmdPort ";
  192. $command .= "-server $server  -db \"toolbox\" -subset \"";
  193. ($subset = $in{'subset'}) =~ s/\\0/\;/g;
  194. $command = $command . $subset . "\"";
  195.  
  196. $command = $command . " -kywd \"$in{'keywords'}\""    if ($in{'keywords'});
  197. $command = $command . " -title \"$in{'doctitle'}\""    if ($in{'doctitle'} && !$in{'keywords'});
  198. $command = $command . " -fname \"$in{'filename'}\""    if ($in{'filename'});
  199. $command = $command . " -after \"$in{'after'}\""    if ($in{'after'});
  200. $command = $command . " -before \"$in{'before'}\""    if ($in{'before'});
  201.  
  202.  
  203. ###################################################
  204. # Run oasiscmd, and pipe output to OASIS filehandle
  205. print "<PRE><BR>Output of: $command\n</PRE>\n"        if ($in{'debug'});
  206. open(OASIS, "-|") || exec ($command);
  207. @oasis = <OASIS>;
  208. close(OASIS);
  209.  
  210.  
  211. #####################################################
  212. # Special subroutine to sort output by title and path
  213. sub sort_oasis {
  214.     local($doca,$docb);
  215.     local($patha,$pathb);
  216.  
  217.     ($doca,$patha) = ($a =~ /\d+\.\s+(.*)\s+\d+\s*(\S*)$/);
  218.     ($docb,$pathb) = ($b =~ /\d+\.\s+(.*)\s+\d+\s*(\S*)$/);
  219.  
  220.     if ($doca eq $docb) {
  221.         $patha cmp $pathb;
  222.     } else {
  223.         $doca cmp $docb;
  224.     }
  225. }
  226.  
  227. if ($oasis[0] =~ /No Items Found/ ) {
  228.     # If no results... 
  229.     print "<B>No documents found matching search criteria.</B><P>\n";
  230.     print "<BR>$oasis[0]\n<P>\n"    if ($in{'debug'});
  231. } elsif ($oasis[1] =~ /Usage:/ || $#oasis < 0) {
  232.     # Server error
  233.     print "<P><B>The oksvr document search engine is not responding.</B><BR>\n";
  234.     print "<P>Please consult the <a href=\"../../sifttree.html\">OasisIII \n";
  235.     print "Search Tool Operability Issues</a> document for an \n";
  236.     print "explanation of how to [re-]activate the oksvr server program.<P>\n";
  237.     print "<BR>$oasis[1]\n<P>\n"    if ($in{'debug'} && $oasis[1]);
  238. } else {
  239.     # It worked, generate search output
  240.     ($pid) = ($oasis[0] =~ /^0\.\s+(\d+)/);     # Get oasiscmd pid
  241.     shift(@oasis) if ($pid);
  242.     print "<PRE>oasiscmd pid = $pid\n<BR></PRE>\n"      if ($in{'debug'});
  243.     @oasis = &remove_dups(@oasis);
  244.     $count = $#oasis + 1;
  245.     print "Search located $count document";
  246.     print "s"        if ($count > 1);
  247.     print "<BR>\n";
  248.     print "Note:  documents ending in <code>.html</code> show up with their";
  249.     print " title instead of their path+filename.<br>\n" ;
  250.     print "<B>Select the document you wish to view:</B>\n";
  251.  
  252.     print "<MENU>\n";
  253.     foreach $_ (sort sort_oasis @oasis) {
  254.     ($ptr,$doc,$type,$path) = (/(\d+)\.\s+(.*)\s+(\d+)\s+(\S+)/);
  255.  
  256.             print "<br>ptr=`",$ptr,"';  doc=`",$doc,"';  type=`",$type,"';  path=`",$path,"'<br>"   if ($in{'debug'});
  257.  
  258.         # doc will equal path+filename UNLESS "$doc ends in .html
  259.         # if this is the case the string inside <title>...</title>
  260.         # is what gets assigned to the $doc field.  when doc IS a
  261.         # .html file, the following substitution properly fails.
  262.             if ($doc =~ s/^all\/cd\d+\///) {
  263.                 undef;
  264.             } else {
  265.                 $doc =~ s/^all\///;
  266.             }
  267.  
  268.         # strip off $OksvrSearchRoot from the absolute path and replace 
  269.         # this with "/toolbox" so links for "path" are properly 
  270.         # defined for the http server to understand.  this all occurs
  271.         # within the actual realm of the /toolbox/searchtools/toolbox/all 
  272.         # subtree, which consists entirely of links back up to the actual
  273.         # TOP-OF-TREE (HUB) under /toolbox;  this searchtools/toolbox/all 
  274.         # directory of links is what the Fulcrum oksvr index files in
  275.         # /toolbox/searchtools/toolbox/toolbox.* uses to simulate the
  276.         # top-of-tree used to complete file retrieval when doing searches
  277.         # inside OasisIII.
  278.  
  279.             if ($path =~ s/.*\/toolbox\/searchtools\/toolbox\/all\///) {
  280.                 if ($path =~ s/^(cd\d+)\///) {
  281.                     $cur_cd = $1;
  282.                 } else {
  283.                     undef $cur_cd;
  284.                 }
  285.                 $path = "/toolbox/$path";
  286.             }
  287.         
  288.     if (! $path) {
  289.         ($ptr,$doc,$type,$path) = (/(\d+)\.\s+(.*)\s+(\d+)\s*(\/*\S*)$/);
  290.             print "<LI><A HREF=\"/toolbox/www/cgi-bin/oretrieve-cgi?$ptr\">$doc</A>\n";
  291.     } else {
  292.             # If the document is local, generate a URL rather than a call
  293.             # to oasiscmd to retrieve the document
  294.             print "<LI><A HREF=\"$path\">$doc</A>\n";
  295.     }
  296.     }
  297.     print "</MENU>\n";
  298. }
  299.  
  300. &footer;
  301.  
  302.